<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <style type="text/css">

        #app{
            width:400px;
            margin: 150px auto;
        }
        #main{
            background-image: url("image/admin_login_background.jpg");
            background-repeat: no-repeat;
            background-size: cover;
        }
    </style>

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body id="main">


    <div id="app">
        <el-form :model="admininfo" :rules="rules" ref="admininfo" label-width="100px" class="demo-ruleForm">
            <el-form-item label="账号：" prop="adminname">
                <el-input v-model="admininfo.adminname" type="text" style="width: 300px;"></el-input>
            </el-form-item>
            <el-form-item label="密码：" prop="password">
                <el-input v-model="admininfo.password"  type="password" style="width: 300px"></el-input>
            </el-form-item>
            <el-form-item style="text-align: center">
                <el-button type="primary" @click=login()>登录</el-button>
                <el-button @click=reset()>重置</el-button>
            </el-form-item>
        </el-form>

</div>
<script>
    var app=new Vue({
        el:"#app",
        data:{
            admininfo:{},
            rules:{
                adminname: [
                    { required: true, message: '请输入账号', trigger: 'blur' },
                    { min: 2, max: 11, message: '长度在 2 到 11 个字符', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 2, max: 8, message: '长度在 2 到 8 个字符', trigger: 'blur' }
                ]
            }
        },
        methods:{
            login:function(){
                app.$refs["admininfo"].validate((valid) => {
                    if (valid) {
                        $.post("/cai/sys/login",app.admininfo,function(backData){
                            if(backData.code==1){
                                window.location.href="adminmain.html";
                            }else {
                                app.$notify.error({
                                    title: '温馨提示',
                                    message: backData.msg,
                                    position: 'top-right'
                                });
                            }
                        });
                    }
                });
            },
            reset:function(){
                app.$refs["admininfo"].resetFields();
            }
        }
    });
</script>

</body>
</html>
